package leet.ku._328;

class ListNode {
	int val;
	ListNode next;

	ListNode(int x) {
		val = x;
	}
}

public class Solution {
	
	public ListNode oddEvenList(ListNode head) {
		if (head == null)
			return null;
		
		ListNode now = head;
		ListNode even = head.next;
		boolean check = true;
		
		while (now.next != null) {
			ListNode p = now.next;
			if (p.next == null && check)
				now.next = even;
			else
				now.next = p.next;
			now = p;
			check = !check;
		}
		if (check)
			now.next = even;
		return head;
	}
}